package senior.ListExer.Exer4;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * ArrayList和LinkedList比较性能（操作加入新值100000次，随机删除100个值，比较时间）
 * @author shkstart
 * @creat 2022-04-15:25
 */
public class CompareTest {
    public static void main(String[] args) {
        List arrayList = new ArrayList();
        long startTime = System.currentTimeMillis();
        for(int i = 0;i < 100000;i++){
            arrayList.add(i);
        }
        for(int i = 0;i < 100;i++){
            Random random = new Random();
            int i1 = random.nextInt(100000);
            arrayList.remove(i1);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("ArrayList花费了：" + (endTime - startTime));

        List linkedList = new LinkedList();
        long startTime1 = System.currentTimeMillis();
        for(int i = 0;i < 100000;i++){
            linkedList.add(i);
        }
        for(int i = 0;i < 100;i++){
            Random random = new Random();
            int i1 = random.nextInt(100000);
            linkedList.remove(i1);
        }
        long endTime1 = System.currentTimeMillis();
        System.out.println("LinkedList花费了：" + (endTime1 - startTime1));

    }
}
